﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;


using ZhimeiSoft.Framework.Client.Base;
using ZhimeiSoft.Framework.Client.Utils;
using ZhimeiSoft.Framework.Common.Enums;

using ZhimeiSoft.CharmManager.DOL;
using ZhimeiSoft.CharmManager.Client.Manager;
using ZhimeiSoft.CharmManager.Client.Interface;

namespace ZhimeiSoft.CharmManager.Client.Forms
{
    public partial class frmToDoListInfo : FormBase
    {
        private DBEntityToDoList todoListInfo = null;
        private DataSet dsEmployeeInfo;
        private ControlClassModeEnum _mode = ControlClassModeEnum.emInsert;

        public ControlClassModeEnum Mode 
        {
            get { return _mode; }
            set { _mode = value; }
        }

        public frmToDoListInfo(DataSet dsEmployee):base()
        {
            InitializeComponent();
            this.dsEmployeeInfo = dsEmployee;
        }
        public frmToDoListInfo(DataSet dsEmployee, DBEntityToDoList todoList)
            :this(dsEmployee)
        {
            todoListInfo = (DBEntityToDoList)todoList.Clone();

        }
        private void frmToDoListInfo_Shown(object sender, EventArgs e)
        {
            toDoListInfoControl.InitDateControl(DateTime.Now, dsEmployeeInfo, todoListInfo);
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            string error = string.Empty;
            bool bFlag = false;
            if (_mode == ControlClassModeEnum.emInsert)
            {
                DBEntityToDoList todoInfo = new DBEntityToDoList();
                bFlag = toDoListInfoControl.GetToDoListInfo(ref todoInfo, out error);
                if (bFlag == false)
                {
                    MsgBox.MsgInfo(error);
                    return;
                }

                bFlag = BussinessProxyManager.Instance.InsertToDoList(todoInfo, out error);
                if (bFlag == false)
                {
                    MsgBox.MsgInfo("新增待办事项失败\r\n" + error);
                    return;
                }
                else
                {
                    MsgBox.MsgInfo("保存成功。");
                    this.DialogResult = DialogResult.OK;
                }
            }
            else if (_mode == ControlClassModeEnum.emEdit)
            {
                bFlag = toDoListInfoControl.GetToDoListInfo(ref todoListInfo, out error);
                if (bFlag == false)
                {
                    MsgBox.MsgInfo(error);
                    return;
                }

                bFlag = BussinessProxyManager.Instance.UpdateToDoList(todoListInfo, out error);
                if (bFlag == false)
                {
                    MsgBox.MsgInfo("更新代办事项失败\r\n" + error);
                    return;
                }
                else
                {
                    MsgBox.MsgInfo("保存成功。");
                    this.DialogResult = DialogResult.OK;
                }
            }
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
